package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;*/
import org.springframework.stereotype.Component;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.LocationTypeDao;
import com.hy.erp.inventory.dao.PositionTypeDao;
import com.hy.erp.inventory.dao.interfaces.ILocationTypeDao;
import com.hy.erp.inventory.pojo.LocationType;
import com.hy.erp.inventory.pojo.interfaces.ILocationType;
import com.hy.erp.inventory.service.interfaces.ILocationTypeService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:18:34</li>
 * <li>类型名称：LocationTypeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
//@ Name ( "locationTypeService" )
///@ Scope ( ScopeType.STATELESS )
//@ Stateless
@Component("locationTypeService" )
public class LocationTypeService extends AbstractBusinessService<LocationTypeDao>  implements ILocationTypeService{

	
	private LocationTypeDao locationTypeDao=null;
	
	

	@Resource(name="locationTypeDao")
	public void setLocationTypeDao(LocationTypeDao locationTypeDao) {
		this.locationTypeDao = locationTypeDao;
	}
	@ Override
	public boolean addLocationType (
										LocationType locationType )
	{

		if ( null == locationType)
		{
			return true ;
		}
		
		else
		{
			//System.out
			//		.println("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh");

			//ILocationTypeDao locationTypeDao = (ILocationTypeDao) this
			//		.getDao(ILocationType.class);

			return locationTypeDao.persist(locationType);
		}
		
	
	
	
	
	
	
	
	}

	@ Override
	public boolean modifyLocationType (
										LocationType locationType )
	{







		if ( ( null == locationType )
			     || ( null == locationType
			                                .getIdentifier ( ) )
			     || ( locationType
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{

			//ILocationTypeDao locationTypeDao = (ILocationTypeDao) this
				//	.getDao(ILocationType.class);
	
				if ( null == locationTypeDao )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (locationTypeDao
				                  .merge ( locationType ) != null ) ;
			}
		
	
	
	
	
	
	
	
	}

	@ Override
	public Integer removeLocationType (
										String [ ] locationTypeIds )
	{







		if ( ( null == locationTypeIds)
			     || ( locationTypeIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{



			//ILocationTypeDao locationTypeDao = (ILocationTypeDao) this
				//	.getDao(ILocationType.class);

				return locationTypeDao
				                .remove ( locationTypeIds ) ;
			}
	
	
	
	
	
	
	
	}

	@ Override
	public String [ ] addLocationType (
										Object [ ] locationType )
	{


		if ( null == locationType)
		{
			return null ;
		}
		
		else
		{
			

			//ILocationTypeDao locationTypeDao = (ILocationTypeDao) this
				//	.getDao(ILocationType.class);

			LocationType[] locationTypes=new LocationType[locationType.length];
						for(int i=0;i<locationType.length;i++)
						{
							LocationType locationType2=( LocationType ) locationType[i];
							locationTypes[i]=locationType2;
						}
						return locationTypeDao
						                .persist ( locationTypes ) ;
			
		}
		
	
	
	
	
	
	
	
	
	}

	@ Override
	public List < LocationType > getAllLocationType ( )
	{

		//ILocationTypeDao locationTypeDao =
          //  ( ILocationTypeDao ) this
            //                   .getDao ( ILocationType.class ) ;



		return locationTypeDao
		                .find ( ) ;
	}

	@ Override
	public String [ ] modifyLocationType (
											Object [ ] locationType )
	{



		if ( null == locationType)
		{
			return null ;
		}
		
		else
		{
			

			//ILocationTypeDao locationTypeDao =
			  //                     ( ILocationTypeDao ) this
			    //                                      .getDao ( ILocationType.class ) ;

			LocationType[] locationTypes=new LocationType[locationType.length];
						for(int i=0;i<locationType.length;i++)
						{
							LocationType locationType2=( LocationType ) locationType[i];
							locationTypes[i]=locationType2;
						}
						return locationTypeDao.merge  ( locationTypes ) ;
			
		}
	
	}
	@Override
	public LocationType findLocationTypeById(String id) {
		return locationTypeDao.findByIdentifier(id);
		//return null;
	}


}
